@extends('admin/layout/master')
@section('title', 'config列表')
@section('title2', 'config列表')

@section('static')
    <script src="/plus/layui-v2.4.5/layui.js"></script>
@endsection

@section('action')
    <a class="layui-btn layui-btn-small layui-btn-normal usersAdd_btn" href="{{ url('/admin/configs/create') }}"><i class="layui-icon"></i>添加</a>
@endsection

@section('content')
    <div style="padding: 10px;">
        <form class="layui-form" action="{{ url('/admin/configs/update_all') }}" method="post" id="mainform">
            <div class="layui-tab layui-tab-card">
                <ul class="layui-tab-title">
                    @foreach($data ?? '' as $k=>$v)
                        <li <?php if($k == "0"){echo 'class="layui-this"';} ?>>{{ $v['name'] }}</li>
                    @endforeach
                </ul>
                <div class="layui-tab-content">
                    @foreach($data ?? '' as $k=>$v)
                        <div class="layui-tab-item <?php if($k == "0"){echo 'layui-show';} ?> ">
                            <table class="layui-table" lay-size="sm">
                                <colgroup>
                                    <col width="20%">
                                    <col width="50%">
                                    <col>
                                    <col width="120">
                                </colgroup>
                                <thead>
                                <tr>
                                    <th>参数说明</th>
                                    <th>参数值</th>
                                    <th>变量名</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($v['data'] as $v2)
                                    <tr>
                                        <td>{{ $v2['info'] }}</td>
                                        <td>
                                            <?php if($v2["type"] == "text"){
                                            ?>
                                            <textarea name="{{ $v2['name'] }}" class="layui-textarea">{{ $v2['value'] }}</textarea>
                                            <?php
                                            }else{ ?>
                                            <input type="text" name="{{ $v2['name'] }}" class="layui-input cmsName" lay-verify="required" value="{{ $v2['value'] }}">
                                            <?php } ?>
                                        </td>
                                        <td>{{ $v2['name'] }}</td>
                                        <td>
                                            <a href="{{ url('/admin/configs/edit',["id"=>$v2['id']]) }}" class="layui-btn layui-btn-normal layui-btn-xs">编辑</a>
                                            <a href="{{ url('/admin/configs/destroy',["id"=>$v2['id']]) }}" data-id="1" data-opt="del" class="layui-btn layui-btn-danger layui-btn-xs">删除</a>
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div>
                    @endforeach
                </div>
            </div>

            <div class="layui-form-item" style="text-align: center;">
                {{ csrf_field() }}
                <button class="layui-btn layui-btn-sm" lay-submit>提交</button>
                <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">重置</button>
            </div>
        </form>
        <script>
            //注意：选项卡 依赖 element 模块，否则无法进行功能性操作
            layui.use('element', function(){
                var element = layui.element;
                //…
            });
        </script>
    </div>
@endsection

@section('layuijs')
    <script>
        //一般直接写在一个js文件中
        layui.use(['layer', 'form'], function(){
            var layer = layui.layer
                    ,form = layui.form;
            form.on('checkbox(allselector)', function(data){
                var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
                child.each(function(index, item){
                    item.checked = data.elem.checked;
                });
                form.render('checkbox');
            });
        });
    </script>
@endsection